package com.ExaminStudy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class LuckFanRen {
   public static List<People>peoples=new ArrayList<>();
    public static void main(String[] args) {
        Random r=new Random();
        for (int i = 1; i <=100 ; i++) {
            while (true) {
                int code = r.nextInt(200) + 1;
                if (check(code)) {
                    People p = new People(code, i);
                    peoples.add(p);
                    break;
                }
            }
        }
        System.out.println(peoples);
        while(peoples.size()>1){
            List<People>temp=new ArrayList<>();
            for (int i = 1; i < peoples.size() ; i+=2) {
                People p=peoples.get(i);
                temp.add(p);
            }
            peoples=temp;
        }
        People luckPeople=peoples.get(0);
        System.out.println(luckPeople);

    }
    public static boolean check(int code){
        for (People people : peoples) {
            for (int i = 0; i < peoples.size() ; i++) {
                if(code==people.getCode()){
                    return false;
                }
            }
        }
        return true;
    }
}
class People{
     private int code;
    private int location;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getLocation() {
        return location;
    }

    public void setLocation(int location) {
        this.location = location;
    }

    public People(int code, int location) {
        this.code = code;
        this.location = location;
    }

    public People() {
    }

    @Override
    public String toString() {
        return "People{" +
                "code=" + code +
                ", location=" + location +
                '}';
    }
}
